package ubadb.core.testDoubles;

import ubadb.core.common.Page;
import ubadb.core.common.PageId;
import ubadb.core.components.bufferManager.bufferPool.BufferFrame;
import ubadb.core.components.bufferManager.bufferPool.BufferPool;
import ubadb.core.exceptions.BufferPoolException;
import static org.junit.Assert.*;

public class MockBufferPool implements BufferPool {

	private PageId lastIsPageInPoolArgument;
	private PageId lastGetBufferFrameArgument;
	private PageId lastHasSpaceArgument;
	private Page lastAddNewPageArgument;
	private PageId lastRemovePageArgument;
	private PageId lastFindVictimArgument;
	private boolean countPagesInPoolWasCalled;
	private int pageCount;

	@Override
	public boolean isPageInPool(PageId pageId) {
		lastIsPageInPoolArgument =  pageId;
		return false;
	}

	@Override
	public BufferFrame getBufferFrame(PageId pageId) throws BufferPoolException {
		lastGetBufferFrameArgument = pageId;
		return null;
	}

	@Override
	public boolean hasSpace(PageId pageToAddId) {
		lastHasSpaceArgument = pageToAddId;
		return false;
	}

	@Override
	public BufferFrame addNewPage(Page page) throws BufferPoolException {
		lastAddNewPageArgument = page;
		return null;
	}

	@Override
	public void removePage(PageId pageId) throws BufferPoolException {
		lastRemovePageArgument = pageId;
	}

	@Override
	public BufferFrame findVictim(PageId pageIdToBeAdded)
			throws BufferPoolException {
		lastFindVictimArgument = pageIdToBeAdded;
		return null;
	}

	@Override
	public int countPagesInPool() {
		countPagesInPoolWasCalled = true;
		return 0;
	}

	public void verifyCallToIsPageInPool(PageId pageId) {
		assertTrue(lastIsPageInPoolArgument == pageId);		
	}

	public void verifyCallToGetBufferFrame(PageId pageId) {
		assertTrue(lastGetBufferFrameArgument == pageId);		
	}

	public void verifyCallToHasSpace(PageId pageId) {
		assertTrue(lastHasSpaceArgument == pageId);
		
	}

	public void verifyCallToAddNewPage(Page page) {
		assertTrue(lastAddNewPageArgument == page);
		
	}

	public void verifyCallToRemovePage(PageId pageId) {
		assertTrue(lastRemovePageArgument == pageId);		
	}

	public void verifyCallToFindVictim(PageId pageId) {
		assertTrue(lastFindVictimArgument == pageId);		
	}

	public void verifyCallToCountPagesInPool() {
		assertTrue(countPagesInPoolWasCalled);		
	}
	
	public void denyCallToIsPageInPool(PageId pageId) {
		assertFalse(lastIsPageInPoolArgument == pageId);		
	}

	public void denyCallToGetBufferFrame(PageId pageId) {
		assertFalse(lastGetBufferFrameArgument == pageId);		
	}

	public void denyCallToHasSpace(PageId pageId) {
		assertFalse(lastHasSpaceArgument == pageId);
		
	}

	public void denyCallToAddNewPage(Page page) {
		assertFalse(lastAddNewPageArgument == page);
		
	}

	public void denyCallToRemovePage(PageId pageId) {
		assertFalse(lastRemovePageArgument == pageId);		
	}

	public void denyCallToFindVictim(PageId pageId) {
		assertFalse(lastFindVictimArgument == pageId);		
	}

	public void denyCallToCountPagesInPool() {
		assertFalse(countPagesInPoolWasCalled);		
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

}
